<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>devicedetect.vcl</title>
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (Varnish Configuration Language) - Theme (Breeze Dark)"/>
</head><body style="background-color:#232629;color:#cfcfc2"><pre>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># Copyright (c) 2016-2018 Varnish Cache project</span>
<span style="color:#7a7c7d;"># Copyright (c) 2012-2016 Varnish Software AS</span>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># SPDX-License-Identifier: BSD-2-Clause</span>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># Redistribution and use in source and binary forms, with or without</span>
<span style="color:#7a7c7d;"># modification, are permitted provided that the following conditions</span>
<span style="color:#7a7c7d;"># are met:</span>
<span style="color:#7a7c7d;"># 1. Redistributions of source code must retain the above copyright</span>
<span style="color:#7a7c7d;">#    notice, this list of conditions and the following disclaimer.</span>
<span style="color:#7a7c7d;"># 2. Redistributions in binary form must reproduce the above copyright</span>
<span style="color:#7a7c7d;">#    notice, this list of conditions and the following disclaimer in the</span>
<span style="color:#7a7c7d;">#    documentation and/or other materials provided with the distribution.</span>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND</span>
<span style="color:#7a7c7d;"># ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span style="color:#7a7c7d;"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<span style="color:#7a7c7d;"># ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE</span>
<span style="color:#7a7c7d;"># FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span style="color:#7a7c7d;"># DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
<span style="color:#7a7c7d;"># OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
<span style="color:#7a7c7d;"># HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
<span style="color:#7a7c7d;"># LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
<span style="color:#7a7c7d;"># OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
<span style="color:#7a7c7d;"># SUCH DAMAGE.</span>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># detectdevice.vcl - regex based device detection for Varnish</span>
<span style="color:#7a7c7d;"># https://github.com/varnishcache/varnish-devicedetect/</span>
<span style="color:#7a7c7d;">#</span>
<span style="color:#7a7c7d;"># Original author: Lasse Karstensen &lt;lkarsten@varnish-software.com&gt;</span>

<span style="font-weight:bold;">sub</span> devicedetect {
	<span style="font-weight:bold;">unset</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span>;
	<span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;pc&quot;</span>;

	<span style="color:#7a7c7d;"># Handle that a cookie may override the detection alltogether.</span>
	<span style="font-weight:bold;">if</span> (<span style="color:#0099ff;">req.http.Cookie</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)X-UA-Device-force&quot;</span>) {
		<span style="color:#7a7c7d;">/* ;?? means zero or one ;, non-greedy to match the first. */</span>
		<span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#8e44ad;">regsub</span>(<span style="color:#0099ff;">req.http.Cookie</span>, <span style="color:#f44f4f;">&quot;(?i).*X-UA-Device-force=([^;]+);??.*&quot;</span>, <span style="color:#f44f4f;">&quot;\1&quot;</span>);
		<span style="color:#7a7c7d;">/* Clean up our mess in the cookie header */</span>
		<span style="font-weight:bold;">set</span> <span style="color:#0099ff;">req.http.Cookie</span> <span style="color:#27ae60;">=</span> <span style="color:#8e44ad;">regsuball</span>(<span style="color:#0099ff;">req.http.Cookie</span>, <span style="color:#f44f4f;">&quot;(^|; ) *X-UA-Device-force=[^;]+;? *&quot;</span>, <span style="color:#f44f4f;">&quot;\1&quot;</span>);
		<span style="color:#7a7c7d;">/* If the cookie header is now empty, or just whitespace, unset it. */</span>
		<span style="font-weight:bold;">if</span> (<span style="color:#0099ff;">req.http.Cookie</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;^ *$&quot;</span>) { <span style="font-weight:bold;">unset</span> <span style="color:#0099ff;">req.http.Cookie</span>; }
	} <span style="font-weight:bold;">else</span> {
        <span style="font-weight:bold;">if</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;\(compatible; Googlebot-Mobile/2.1; \+http://www.google.com/bot.html\)&quot;</span> <span style="color:#27ae60;">||</span>
            (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(Android|iPhone)&quot;</span> <span style="color:#27ae60;">&amp;&amp;</span> <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;\(compatible.?; Googlebot/2.1.?; \+http://www.google.com/bot.html&quot;</span>) <span style="color:#27ae60;">||</span>
			(<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(iPhone|Windows Phone)&quot;</span> <span style="color:#27ae60;">&amp;&amp;</span> <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;\(compatible; bingbot/2.0; \+http://www.bing.com/bingbot.htm&quot;</span>)) {
            <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-bot&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)(ads|google|bing|msn|yandex|baidu|ro|career|seznam|)bot&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)(baidu|jike|symantec)spider&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)pingdom&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)facebookexternalhit&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)scanner&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)slurp&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)(web)crawler&quot;</span>) {
			<span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;bot&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)ipad&quot;</span>)        { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-ipad&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)ip(hone|od)&quot;</span>) { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-iphone&quot;</span>; }
		<span style="color:#7a7c7d;">/* how do we differ between an android phone and an android tablet?</span>
<span style="color:#7a7c7d;">		   http://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent */</span>
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)android.*(mobile|mini)&quot;</span>) { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-android&quot;</span>; }
		<span style="color:#7a7c7d;">// android 3/honeycomb was just about tablet-only, and any phones will probably handle a bigger page layout.</span>
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)android 3&quot;</span>)              { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-android&quot;</span>; }
		<span style="color:#7a7c7d;">/* Opera Mobile */</span>
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Opera Mobi&quot;</span>)                  { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-smartphone&quot;</span>; }
		<span style="color:#7a7c7d;">// May very well give false positives towards android tablets. Suggestions welcome.</span>
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)android&quot;</span>)         { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-android&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;PlayBook; U; RIM Tablet&quot;</span>)         { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-rim&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;hp-tablet.*TouchPad&quot;</span>)         { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-hp&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Kindle/3&quot;</span>)         { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-kindle&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Touch.+Tablet PC&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Windows NT [0-9.]+; ARM;&quot;</span> ) {
		        <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;tablet-microsoft&quot;</span>;
		}
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Mobile.+Firefox&quot;</span>)     { <span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-firefoxos&quot;</span>; }
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;^HTC&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;Fennec&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;IEMobile&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;BlackBerry&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;BB10.*Mobile&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;GT-.*Build/GINGERBREAD&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;SymbianOS.*AppleWebKit&quot;</span>) {
			<span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-smartphone&quot;</span>;
		}
		<span style="font-weight:bold;">elsif</span> (<span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)symbian&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)^sonyericsson&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)^nokia&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)^samsung&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)^lg&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)bada&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)blazer&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)cellphone&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)iemobile&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)midp-2.0&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)u990&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)netfront&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)opera mini&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)palm&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)nintendo wii&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)playstation portable&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)portalmmm&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)proxinet&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)windows\ ?ce&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)winwap&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)eudoraweb&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)htc&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)240x320&quot;</span> <span style="color:#27ae60;">||</span>
		    <span style="color:#0099ff;">req.http.User-Agent</span> <span style="color:#27ae60;">~</span> <span style="color:#f44f4f;">&quot;(?i)avantgo&quot;</span>) {
			<span style="font-weight:bold;">set</span> <span style="color:#0099ff;font-style:italic;">req.http.X-UA-Device</span> <span style="color:#27ae60;">=</span> <span style="color:#f44f4f;">&quot;mobile-generic&quot;</span>;
		}
	}
}
</pre></body></html>
